PRINT USING Statement ---------------------------------------------------------------------------- Action Prints strings or numbers using a specified format. Syntax PRINT USING formatstring$; expressionlist {;|,} Remarks The PRINT USING statement uses the following arguments. ----------------------------------------------------------------------------- Argument Description ---------------------------------------------------------------------------- formatstring$ A string literal (or variable) that contains literal characters to print (such as labels) and special formatting characters. The latter determine the field and format of printed strings or numbers. expressionlist The values displayed on the screen. Commas, semicolons, spaces, or tabs can be used in Argument Description ---------------------------------------------------------------------------- tabs can be used in expressionlist to separate items. In contrast with the PRINT statement, delimiters in the expressionlist argument used with PRINT USING have no effect on item placement. {;|,} Determines the screen location of the text cursor for the next screen input or output statement. a semicolon means the text cursor is placed immediately after the last character displayed; a comma means the text cursor is placed at the start of the next print zone. When PRINT USING is used to print strings, you can use one of three formatting characters to format the string field, as described in the following list. ----------------------------------------------------------------------------- Character Rules ---------------------------------------------------------------------------- ! Only the first character in the given string is to be printed. \ \ Prints 2 + n characters from the string, where n is the number of spaces between the two backslashes. For example, if the backslashes are typed with no spaces, two characters are printed; with one space, three characters are printed, and so on. If the field is longer than the string, the string is left-justified in the field and padded with spaces on Character Rules ---------------------------------------------------------------------------- field and padded with spaces on the right. & The string is output without modification. When PRINT USING is used to print numbers, the following special characters can be used to format the numeric field. ----------------------------------------------------------------------------- Character Rules ---------------------------------------------------------------------------- # Represents each digit position. Digit positions are always filled. Character Rules ---------------------------------------------------------------------------- Digit positions are always filled. If the number to be printed has fewer digits than positions specified, the number is right-justified (preceded by spaces) in the field. . Prints a decimal point. A decimal point can be inserted at any position in the field. If the format string specifies that a digit is to precede the decimal point, the digit is always printed (as 0, if necessary). Numbers are rounded as necessary. + Prints the sign of the number (+ or -) before the number (if it appears at the beginning of the Character Rules ---------------------------------------------------------------------------- appears at the beginning of the format string) or after (if it appears at the end). - Prints a negative number with a trailing minus sign if it appears at the end of the format string. ** Fills leading spaces in the numeric field with asterisks. Also specifies positions for two more digits. $$ Prints a dollar sign to the immediate left of the formatted number. Specifies two more digit positions, one of which is the dollar sign. Character Rules ---------------------------------------------------------------------------- **$ Combines effects of double-asterisk and double-dollar-sign symbols. Leading spaces are filled with asterisks and a dollar sign is printed before the number. Specifies three more digit positions, one of which is the dollar sign. When negative numbers are printed, the minus sign appears to the immediate left of the dollar sign. , If the comma appears to the left of the decimal point in a format string, it makes a comma print to the left of every third digit left of the decimal point. If the comma Character Rules ---------------------------------------------------------------------------- of the decimal point. If the comma appears at the end of the format string, it is printed as part of the string. Specifies another digit position. Has no effect if used with exponential (^^^^ or ^^^^^) format. ^^^^ Specifies exponential format. Five carets (^^^^^) allows D+ xxx to be printed for larger numbers. Any decimal point position can be specified. The significant digits are left-justified and the exponent is adjusted. Unless a leading +, trailing +, or - is specified, one digit position is used to the left of the decimal point to print a space or a minus Character Rules ---------------------------------------------------------------------------- point to print a space or a minus sign. _ An underscore in the format string prints the next character as a literal character. A literal underscore is printed as the result of two underscores ( _ _ ) in the format string. If the number to be printed is larger than the specified numeric field, a percent sign (%) is printed in front of the number. If rounding causes the number to exceed the field, a percent sign is printed in front of the rounded number. If the number of digits specified exceeds 24, BASIC generates the error message Illegal function call. Examples The following examples show the use of string- and numeric-formatting characters with PRINT USING. This is an example of using string-formatting characters. CLS ' Clear screen. A$ = "LOOK" . B$ = "OUT" PRINT USING "!"; A$; B$' First characters of A$ and B$. PRINT USING "\ \"; A$; B$' Two spaces between backslashes, ' prints four characters from A$; PRINT USING "\ \"; A$; B$; "!!" ' three spaces prints A$ and ' a blank. PRINT USING "!"; A$;' First character from A$ and PRINT USING "&"; B$' all of B$ on one line. Output LO LOOKOUT LOOK OUT !! LOUT This example shows the effects of different combinations of numeric formatting characters. ' Format and print numeric data. CLS ' Clear screen. PRINT USING "##.##"; .78 PRINT USING "###.##"; 987.654 PRINT USING "##.## "; 10.2, 5.3, 66.789, .234 PRINT USING "+##.## "; -68.95, 2.4, 55.6, -.9 PRINT USING "##.##- "; -68.95, 22.449, -7.01 PRINT USING "**#.# "; 12.39, -0.9, 765.1 PRINT USING "$$###.##"; 456.78 PRINT USING "**$##.##"; 2.34 PRINT USING "####,.##"; 1234.5 PRINT USING "##.##^^^^"; 234.56 PRINT USING ".####^^^^-"; -888888 PRINT USING "+.##^^^^^"; 123 PRINT USING "_!##.##_!"; 12.34 PRINT USING "##.##"; 111.22 PRINT USING ".##"; .999 Output 0.78 987.65 10.20 5.30 66.79 0.23 -68.95 +2.40 +55.60 -0.90 68.95- 22.45 7.01- *12.4 *-0.9 765.1 $456.78 ***$2.34 1,234.50 2.35E+02 .8889E+06- +.12E+003 !12.34! %111.22 %1.00